﻿Imports System.Data
Imports AugmentLib.Database
Imports System.Configuration.ConfigurationManager

Partial Class Diagnose
    Inherits System.Web.UI.Page
    Dim tb As New DataTable()
    Dim dr As DataRow

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("StaffId") Is Nothing Then
            Response.Redirect("Default.aspx")
        ElseIf Session.Item("StaffType").ToString = "2" Then
            Response.Redirect("Default.aspx")
        End If

    End Sub

    Protected Sub runBtn_Click(sender As Object, e As EventArgs) Handles runBtn.Click
        Dim retval = accessDB()
        createtable()
        Call Addnewrow()
    End Sub

    Protected Function accessDB() As String
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable
        Try
            objDB.OpenConnection()
            objDB.InitDbTrans()
            objDB.dbVariable.SQLString = queryText.Text

            objDB.dbVariable.SQLString = "SELECT CountryID,Country FROM AW_Country ORDER BY Country"
            objDB.FillData(TempDT, "Country", Database.SQLCommandType.NormalString)

            objDB.ExecuteQuery(False) 'Insert / Update / Delete
            objDB.DbTransCommit()
        Catch ex As Exception
            If objDB.dbVariable.objConn.State = Data.ConnectionState.Open Then
                objDB.DbTransRollback()
                objDB.CloseConnection()
            End If
        Finally

        End Try
        Return "YES"
    End Function

    Public Sub createtable()

        tb.Columns.Add("Prod_NO", GetType(String))
        tb.Columns.Add("Prod_Name", GetType(String))
        tb.Columns.Add("Order_Date", GetType(String))
        tb.Columns.Add("Quantity", GetType(String))

        dr = tb.NewRow()
        dr("Prod_NO") = "101"
        dr("Prod_Name") = "Product1"
        dr("Order_Date") = "12/06/2012"
        dr("Quantity") = "50"
        tb.Rows.Add(dr)

        dr = tb.NewRow()
        dr("Prod_NO") = "102"
        dr("Prod_Name") = "Product2"
        dr("Order_Date") = "15/06/2012"
        dr("Quantity") = "70"
        tb.Rows.Add(dr)
        Gv1.DataSource = tb
        Gv1.DataBind()
        ViewState("table1") = tb
    End Sub

    Sub Addnewrow()
        tb = DirectCast(ViewState("table1"), DataTable)
        dr = tb.NewRow()
        dr("Prod_NO") = "test1"
        dr("Prod_Name") = "txtb2.Text"
        dr("Order_Date") = "txtb3.Text"
        dr("Quantity") = "txtb4.Text"
        tb.Rows.Add(dr)
        Gv1.DataSource = tb
        Gv1.DataBind()
    End Sub
End Class
